package com.example.drivingtraininghall;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TrainingHallAdapter extends ArrayAdapter<TrainingHall> {
	
	private int resourceId;

	public TrainingHallAdapter(Context context, int textViewResourceId,
			List<TrainingHall> objects) {
		super(context, textViewResourceId, objects);
		resourceId = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TrainingHall trainingHall = getItem(position);
		View view;
		ViewHolder viewHolder;
		if (convertView == null) {
			view = LayoutInflater.from(getContext()).inflate(resourceId, null);
			viewHolder = new ViewHolder();
			viewHolder.hallImage = (ImageView) view.findViewById(R.id.hall_pic);
			viewHolder.hallName = (TextView) view.findViewById(R.id.hall_name);
			viewHolder.hallAddress = (TextView) view.findViewById(R.id.hall_address);
			viewHolder.remainNum = (TextView) view.findViewById(R.id.remain_num);
			view.setTag(viewHolder);
		} else {
			view = convertView;
			viewHolder = (ViewHolder) view.getTag();
		}
		viewHolder.hallImage.setImageResource(trainingHall.getImageHall());
		viewHolder.hallName.setText(trainingHall.getName());
		viewHolder.hallAddress.setText(trainingHall.getAddress());
		viewHolder.remainNum.setText(trainingHall.getRemain());
		return view;
	}
	
	class ViewHolder {
		
		ImageView hallImage;
		
		TextView hallName;
		
		TextView hallAddress;
		
		TextView remainNum;
		
	}
	

}
